import { AxiosPromise, AxiosResponse } from 'axios'
import { api } from '../boot/axios'
import { OldMainRecordI } from './type'


// Which record MTR old repair order records

function url(s: string) {
  if (s==''){
    return ['/api/maintenance', ''].join('/')
  }
  return ['/api/maintenance', s.replace('/', ''), ''].join('/')
}
export function mainRecord(stock_code: string, serial_no: string, complete_status: boolean){
    return api({
      url:url('get_maintenance_records'),
      method: 'post',
      data:{
        stock_code:stock_code.toUpperCase(),
        serial_no: serial_no,
        complete_status: complete_status
      }
    })
  }

  export function getMainRecord(mainRecordId: number){
    return api({
      url:url('get_maintenance_record'),
      method: 'post',
      data:{
        main_record_id :mainRecordId,
      }
    })
  }

  export async function list(currentPage: number, rowsPerPage: number){
    const res = await api({
      url: url(''),
      method: 'get',
      // params:{
      //   page: currentPage,
      //   rows_per_page: rowsPerPage,
      //   finding:'FF'
      // }
    })
    return res.data as OldMainRecordI[]
  }
  
  export async function get (id:number){
    const res = await api({
      url: url(''+id),
      method: 'get',
    })
    return res.data as OldMainRecordI
  }
  
  export async function patch (id:number,data:Partial<OldMainRecordI>={}){
    const res = await api({
      url: url(''+id),
      method: 'patch',
      data
    })
    return res.data as OldMainRecordI
  }
  
  export async function create (data:Partial<OldMainRecordI>={}){
    const res = await api({
      url: url(''),
      method: 'post',
      data
    })
    return res.data as OldMainRecordI
  }
  
  